﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace BitcoinMarket.ViewModels
{
    public class AppSettingsCurrencyViewModel : INotifyPropertyChanged
    {
        private AppCurrencySettings settings = new AppCurrencySettings();

        private string _currencyTitle;
        /// <summary>
        /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
        /// </summary>
        /// <returns></returns>
        public string CurrencyTitle
        {
            get
            {
                return _currencyTitle;
            }
            set
            {
                if (value != _currencyTitle)
                {
                    _currencyTitle = value;
                    NotifyPropertyChanged("CurrencyTitle");
                }
            }
        }


        private bool _currencyToppedDefault;
        /// <summary>
        /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
        /// </summary>
        /// <returns></returns>
        public bool CurrencyToppedDefault
        {
            get
            {
                return _currencyToppedDefault;
            }
            set
            {
                if (value != _currencyToppedDefault)
                {
                    _currencyToppedDefault = value;
                    NotifyPropertyChanged("CurrencyToppedDefault");
                }
            }
        }

        private bool _currencyTopped;
        /// <summary>
        /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
        /// </summary>
        /// <returns></returns>
        public bool CurrencyTopped
        {
            get
            {
                _currencyTopped = settings.GetValueOrDefault<bool>(this.CurrencyTitle, this.CurrencyToppedDefault);

                return _currencyTopped;
            }
            set
            {
                if (value != _currencyTopped)
                {
                    _currencyTopped = value;
                    //save the setting
                    settings.AddOrUpdateValue(this.CurrencyTitle, value);

                    NotifyPropertyChanged("CurrencyTopped");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

    }
}


